home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / mail / qwkspec.zip / NDX.TXT < prev    next >
Text File  |  1991-05-28  |  4KB  |  129 lines

  1.  
  2.  
  3.  
  4.                            Format of Index files
  5.  
  6.       Index files are named XXX.NDX (where XXX is the conference
  7.       number padded with leading zeros to make it three characters
  8.       long.  There is one *.NDX file for each conference chosen that
  9.       contains messages in the MESSAGES.DAT file.
  10.  
  11.       The *.NDX file contain records five characters long that point
  12.       to each message in that conference.
  13.  
  14.  
  15.       NdxRecord = Record
  16.         MsgPointer: BasicReal
  17.         Conference: Byte;
  18.         End;
  19.  
  20.       The BasicReal is a four byte number in BASIC MKS$ format.
  21.  
  22.  
  23.       The following is a sample program unit for TurboPascal that
  24.       converts between BasicReal format and LongInt format.
  25.  
  26. ------------------------------------------------------------------------------
  27.  
  28. Unit BasicConvert;
  29.  
  30. Interface
  31.   Function BasicReal2Long(InValue: LongInt): LongInt;
  32.                 {Convert Basic Short Reals to LongInts}
  33.  
  34.   Function Long2BasicReal(InValue: LongInt): LongInt;
  35.                 {Convert LongInts to Basic Short Reals}
  36.  
  37. Implementation
  38.  
  39. Function BasicReal2Long(InValue: LongInt): LongInt;
  40.  
  41.   Var
  42.   Temp: LongInt;
  43.   Negative: Boolean;
  44.   Expon: Integer;
  45.  
  46.   Begin
  47.     If InValue And $00800000 <> 0 Then
  48.       Negative := True
  49.     Else
  50.       Negative := False;
  51.     Expon := InValue shr 24;
  52.     Expon := Expon and $ff;
  53.     Temp := InValue and $007FFFFF;
  54.     Temp := Temp or $00800000;
  55.     Expon := Expon - 152;
  56.     If Expon < 0 Then Temp := Temp shr Abs(Expon)
  57.       Else Temp := Temp shl Expon;
  58.     If Negative Then
  59.       BasicReal2Long := -Temp
  60.     Else
  61.       BasicReal2Long := Temp;
  62.     If Expon = 0 Then
  63.       BasicReal2Long := 0;
  64.   End;
  65.  
  66.  
  67. Function Long2BasicReal(InValue: LongInt): LongInt;
  68.   Var
  69.   Negative: Boolean;
  70.   Expon: LongInt;
  71.  
  72.   Begin
  73.   If InValue = 0 Then
  74.     Long2BasicReal := 0
  75.   Else
  76.     Begin
  77.     If InValue < 0 Then
  78.       Begin
  79.       Negative := True;
  80.       InValue := Abs(InValue);
  81.       End
  82.     Else
  83.       Negative := False;
  84.     Expon := 152;
  85.     If InValue < $007FFFFF Then
  86.       While ((InValue and $00800000) = 0) Do
  87.         Begin
  88.         InValue := InValue shl 1;
  89.         Dec(Expon);
  90.         End
  91.     Else
  92.       While ((InValue And $FF000000) <> 0) Do
  93.         Begin
  94.         InValue := InValue shr 1;
  95.         Inc(Expon);
  96.         End;
  97.     InValue := InValue And $007FFFFF;
  98.     If Negative Then
  99.       InValue := InValue Or $00800000;
  100.     Long2BasicReal := InValue + (Expon shl 24);
  101.     End;
  102.   End;
  103.  
  104. End.
  105.  
  106. ------------------------------------------------------------------------------
  107.  
  108. A quick and dirty conversion (handles positive numbers only) is possible
  109. with the following expression:
  110.  
  111. MKSToNum := ((x AND NOT $ff000000) OR $00800000)
  112.              SHR (24 - ((x SHR 24) AND $7f));
  113.  
  114. ------------------------------------------------------------------------------
  115.  
  116.       The number contained in the MsgPointer is the record number
  117.       (128 byte records - starting numbering from record 1 not 0)
  118.       of the message header.  Note that since the 1st record contains
  119.       packet header, the lowest MsgPointer that can exist is 2.
  120.  
  121.       Some message readers will reformat the *.NDX files so that the
  122.       MsgPointer becomes a LongInt fileseek position (using a record
  123.       size of 1).  To determine which type of index you are reading
  124.       you should look at the size of the number.  Any BasicReal will
  125.       appear as a huge number that would unlikely ever be a byte
  126.       seek positon.
  127.  
  128.  
  129.